package com.qidian.mes.pro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.pojo.pro.ProProcess;
import com.qidian.mes.pojo.pro.ProProcessContent;
import com.qidian.mes.pro.mapper.ProProcessContentMapper;
import com.qidian.mes.pro.mapper.ProProcessMapper;
import com.qidian.mes.pro.service.ProProcessContentService;
import com.qidian.mes.pro.service.ProProcessService;
import com.qidian.mes.util.pojo.MESResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 郭靖旖
 * @Company
 * @Time 2023/10/31 17:52
 * @Description
 **/
@Service
public class ProProcessContentServiceImpl implements ProProcessContentService {
    @Autowired
    ProProcessContentMapper proProcessContentMapper;
    @Autowired
    ProProcessMapper proProcessMapper;
    @Override
    public MESResult selectByProcessId(int page, int limit, String processCode) {
        Long processId=proProcessMapper.selectByProcesssCode(processCode).getProcessID();
        PageHelper.startPage(page,limit);
        List<ProProcessContent> list=proProcessContentMapper.selectByProcessId(processId);
        PageInfo<ProProcessContent> pageInfo=new PageInfo<>(list);
        return MESResult.ok(pageInfo);
    }

    @Override
    public MESResult selectByprocessCode(String processCode) {
        System.err.println(proProcessMapper.selectByProcesssCode(processCode).getProcessID());
        return MESResult.ok(proProcessMapper.selectByProcesssCode(processCode).getProcessID());
    }

    @Override
    public MESResult save(ProProcessContent proProcessContent) {
        if (proProcessContentMapper.save(proProcessContent)==1)
        {
            return MESResult.ok();
        }
        else
        {
            return MESResult.duplicate();
        }

    }

    @Override
    public MESResult updateProProcessContent(ProProcessContent proProcessContent) {
        if (proProcessContentMapper.updateProProcessContent(proProcessContent)==1){
            return MESResult.ok();
        }
        else{
            return MESResult.fail();
        }
    }

    @Override
    public MESResult deleteProProcessContent(Long contentId) {
        if (proProcessContentMapper.deleteProProcessContent(contentId)==1){
            return MESResult.ok();
        }
        else {
            return MESResult.fail();
        }
    }
}
